package cn.bugstack.mybatis.session;

import cn.bugstack.mybatis.binding.MapperRegistry;
import cn.bugstack.mybatis.mapping.MappedStatement;

import java.util.HashMap;
import java.util.Map;

public class Configuration {
    //映射注册机
    protected MapperRegistry mapperRegistry = new MapperRegistry(this);

    //映射的语句存在map里
    protected final Map<String , MappedStatement> mapperStatements = new HashMap<>();

    public <T> void addMapper(Class<T> type){
        mapperRegistry.addMapper(type);
    }
    public void addMappedStatement(MappedStatement ms){
        mapperStatements.put(ms.getId(), ms);
    }

    public MappedStatement getMappedStatement(String statement) {
        return mapperStatements.get(statement);
    }

    public <T> T getMapper(Class<T> type, SqlSession sqlSession) {
        return mapperRegistry.getMapper(type, sqlSession);
    }
}
